package d_obje.example3;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;

import com.alibaba.fastjson.JSON;
import com.wang.template.json.JsonLoader;
import com.wang.template.json.JsonRender;
import com.wang.template.json.node.BaseNode;

import Z_bean.Goods;
import Z_bean.Shop;

public class ObjectExample {
	public static void main(String[] args) throws Exception {
		BaseNode node = getNode();
		Object data = getData();
		for (int i = 0; i < 10; i++) {
			long start = System.currentTimeMillis();
			Object obj = JsonRender.render(node, data);
			long time = System.currentTimeMillis() - start;
			System.out.println("耗时" + time+JSON.toJSONString(obj) );
		}

	}

	private static BaseNode getNode() throws Exception {
		String jsonStr = FileUtils
				.readFileToString(new File(ObjectExample.class.getResource("json.json").getPath()), "UTF-8");
		return JsonLoader.load(jsonStr);
	}

	private static Object getData() {
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("retCode", "000000");
		result.put("retMsg", "服务执行成功");
		Shop shop = new Shop();
		shop.setShopId("111");
		shop.setShopName("肯德基文三路店");
		result.put("data", shop);
		shop.setDistance("1.1km");
		List<Goods> goodsList = new LinkedList<Goods>();
		shop.setGoodsList(goodsList);
		for (int i = 0; i < 300; i++) {
			Goods goods = new Goods();
			goods.setId("111" + i);
			goods.setName("汉堡" + i);
			goods.setOriginalPrice("11.99");
			goods.setSalesPrice("9.99");
			goods.setImg("www.baidu.com");
			goodsList.add(goods);
		}
		return result;
	}
}
